package com.account.filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 * User: lixiao
 * Created Date: 2020/4/9 23:08
 *
 * 使用两种方法添加过滤器
 *
 * 1、使用@configuration 注解，创建类集成Filter过滤器，使用fiterRegistrationBean类进行bean注入，并添加相关bean配置。
 *2、使用@WebFilter(filterName = "testFilter",urlPatterns = "/*")注解，
 *
 */
@Configuration
public class FilterConfig {


    //@Bean
    FilterRegistrationBean registrationBean(){
        FilterRegistrationBean bean=new FilterRegistrationBean();
        bean.setFilter(new TestFilter());
        bean.setName("testFilter");
        bean.addUrlPatterns("/*");
        bean.setOrder(1);
        return bean;
    }
}